home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d20 / yuck_200.arc / YUCKNL.C < prev   
C/C++ Source or Header  |  1990-10-29  |  6KB  |  184 lines

  1. #include "yuck.h"                                       /* define miscellany */
  2. /* ========================================================================= */
  3. Byte *    getComma( Byte * p, Byte * Temp )
  4. {
  5.     Byte *    q;
  6.     int    n;
  7.  
  8.     q = strchr( p, ',' );
  9.     if ( q == NULL ) {
  10.         printf( "getComma failed: '%s'\n", p );
  11.         exit( 1 );
  12.         }
  13.     n = min( q - p, STRSIZ );
  14.     if ( q > p ) memcpy( Temp, p, n );
  15.     Temp[n] = EOS;
  16.     assert( Temp, STRSIZ );
  17.     return q + 1;
  18.     }
  19. /* ========================================================================= */
  20. void    parseRec( Byte * Line, tNod * Buf, int Action )
  21. {
  22.     Byte *    p, * q;                                   /* parser pointers */
  23.     long    temp;                                     /* for node# parse */
  24.     static    Byte    Temp[STRSIZ + 1];                  /* temp hold area */
  25.     static    tAd    ad;                           /* last node processed */
  26. /* ------------------------------------------------------------------------- */
  27.     switch ( Action ) {
  28. case 0:        break;                                       /* normal parse */
  29. case 1:        ad.z = ad.n = ad.f = ad.p = 0; return;              /* reset */
  30. case 2:        break;                                    /* no default fill */
  31. default:    return;               /* that's what _I_ call error checking */
  32.         }
  33. /* ------------------------------------------------------------------------- */
  34.     q = getComma( Line, Temp );
  35.     Buf->Type = Node;                                         /* preload */
  36.          if ( stricmp( Temp, "Zone" ) == 0 )
  37.         Buf->Type = Zone;
  38.     else if ( stricmp( Temp, "Region" ) == 0 )
  39.         Buf->Type = Region;
  40.     else if ( stricmp( Temp, "Host" ) == 0 )
  41.         Buf->Type = Host;
  42.     else if ( stricmp( Temp, "Hub" ) == 0 )
  43.         Buf->Type = Hub;
  44.     else if ( stricmp( Temp, "Point" ) == 0 )
  45.         Buf->Type = Point;
  46.     else if ( stricmp( Temp, "Pvt" ) == 0 )
  47.         Buf->Type = Pvt;
  48.     else if ( stricmp( Temp, "Down" ) == 0 )
  49.         Buf->Type = Down;
  50.     else if ( stricmp( Temp, "Boss" ) == 0 ) {
  51.         parseRec( NULL, NULL, 1 );                /* reset ourselves */
  52.         parseAd( q, &ad );
  53.         Buf->a = ad;
  54.         Buf->Type = Node;
  55.         Buf->No = Buf->a.f;
  56.         Buf->Bbs[0] = Buf->City[0] = Buf->Sysop[0] =
  57.         Buf->Tel[0] = Buf->Flags[0] = EOS;
  58.         Buf->Baud = 9600;
  59.         return;
  60.         }
  61. /* ------------------------------------------------------------------------- */
  62.     p = getComma( q, Temp );
  63.     if ( strlen( Temp ) == 0 ) {
  64.         printf( "parseRec: no node# '%s'\n", Line );
  65.         exit( 1 );
  66.         }
  67.     temp = strtol( Temp, &q, 10 );                         /* get node # */
  68.     if ( temp < 0L || temp > 65535L ) {
  69.         printf( "parseRec: bad node# %ld\n", Temp );
  70.         exit( 1 );
  71.         }
  72.     Buf->No = (Word) temp;
  73.     if ( ( inFd199b == Yes || inPointnet == Yes ) && Cfg.keepPvt == Yes )
  74.         if ( Buf->Type == Pvt )
  75.             Buf->Type = Node;             /* keep private points */
  76.     if ( Action == 2 )                                      /* set node# */
  77.         Buf->a.f = Buf->No;
  78.     else {
  79.         Buf->a = ad;                                /* copy defaults */
  80.         switch ( Buf->Type ) {
  81. case Zone:        Buf->a.z = Buf->a.n = Buf->No;
  82.             Buf->a.f = Buf->a.p = 0;
  83.             break;
  84. case Region:
  85. case Host:        Buf->a.n = Buf->No;
  86.             Buf->a.f = Buf->a.p = 0;
  87.             break;
  88. case Point:        Buf->a.p = Buf->No;
  89.             break;
  90. default:        Buf->a.f = Buf->No;
  91.             Buf->a.p = 0;
  92.             break;
  93.             }
  94.         if ( inFd199b == Yes  ) {
  95.             Word    temp;
  96.             temp = Buf->a.f;
  97.             Buf->a = ad;
  98.             Buf->a.p = temp;
  99.             Buf->Type = Point;
  100.             }
  101.         ad = Buf->a;                    /* set default for next time */
  102.         }
  103. /* ------------------------------------------------------------------------- */
  104. /* CLIST supports a special entry format on amigas. if it encounters a line  */
  105. /* of the sort "{type},{node#},->" (note the arrow), it reads the node's     */
  106. /* data from the main nodelist. that doesn't work for points. anyway, since  */
  107. /* Yuck! takes data for non-point systems _always_ from the nodelist, it     */
  108. /* can't hurt to support this format.                                        */
  109. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  110.     if ( inPointnet == Yes && Buf->Type != Point &&
  111.          *p == '-' && p[1] == '>' ) {               /* ",3,->" for amiga */
  112.         *Buf->Bbs = *Buf->City = *Buf->Sysop =
  113.         *Buf->Tel = *Buf->Flags = EOS;
  114.         Buf->Baud = POINTBAUD;
  115.         return;
  116.         }
  117. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  118.     q = getComma( p, Buf->Bbs ); Buf->Bbs[STRSIZ] = EOS;
  119.     p = getComma( q, Buf->City ); Buf->City[STRSIZ] = EOS;
  120.     q = getComma( p, Buf->Sysop ); Buf->Sysop[STRSIZ] = EOS;
  121.     p = getComma( q, Buf->Tel ); Buf->Tel[STRSIZ] = EOS;
  122.     Buf->Baud = (Word) strtol( p, &q, 10 );
  123.     if ( *q != ',' ) {
  124.         printf( "parseRec: no flags '%s'\n", q );
  125.         exit( 1 );
  126.         }
  127.     q ++;
  128.     strncpy( Buf->Flags, q, STRSIZ ); Buf->Flags[STRSIZ] = EOS;
  129.     assert( Buf->Bbs, STRSIZ );
  130.     assert( Buf->City, STRSIZ );
  131.     assert( Buf->Sysop, STRSIZ );
  132.     assert( Buf->Tel, STRSIZ );
  133.     assert( Buf->Flags, STRSIZ );
  134.     }
  135. /* ========================================================================= */
  136. tNod *    newNod( void )
  137. {
  138.     tNod *    p;
  139. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  140.     p = malloc( sizeof( tNod ) );
  141.     if ( p == NULL ) {
  142.         puts( "\nsorry, friend, but i just ran out of memory. currently, i have some" );
  143.         printf( "%u entries stashed away, and that _does_ seem a bit exaggerating.\n", maxpt );
  144.         exit( 99 );
  145.         }
  146.     p->nx = NULL;
  147.     return p;
  148.     }
  149. /* ========================================================================= */
  150. tNod *    addNod( int addCopy, tNod * Node )
  151. {
  152.     tNod *    p;
  153.  
  154.     if ( addCopy ) {                      /* make a copy for list entry? */
  155.         p = newNod();
  156.         *p = *Node;
  157.         }
  158.     else    p = Node;
  159.  
  160.     p->nx = pts;
  161.     pts = p;
  162.     return p;
  163.     }
  164. /* ========================================================================= */
  165. void    delNod( tNod * p )
  166. {
  167.     tNod *    q;
  168.     tNod *    r;
  169.  
  170.     if ( p = pts )                                         /* list head? */
  171.         pts = p->nx;
  172.     else {
  173.         for ( r = pts, q = pts->nx; q != NULL; q = q->nx ) {
  174.             if ( q == p ) {
  175.                 r->nx = q->nx;
  176.                 break;
  177.                 }
  178.             r = q;
  179.             }
  180.         }
  181.     free( p );
  182.     }
  183. /* ========================================================================= */
  184.